import axios from 'axios'

const Service = axios.create({

    timeout:8000,   //超时    
    baseURL:" http://localhost:3000/",
    headers:{
        // 设置头信息
        "Content-Type": "application/json;charset=utf-8",        
    }
})

/**///请求拦截
Service.interceptors.request.use(config => {    
    return config
})

/**///响应拦截
Service.interceptors.response.use(response => {
    
    const data = response.data  //请求得到的全部的数据        
    if (!data.data ) {                
        return data
    }
    return data  //得到请求的所有的数据

}, error => {
    console.log(error);    
})

/**///get 请求
export const get = config => {
    return Service({
        ...config,
        method: "get",
        params: config.data        
    })
}

export const post = config => {
    return Service({
        ...config,
        method: "post",
        data: config.data        
    })
}

export const del = config => {
    return Service({
        ...config,
        method: "delete",         
    })
}

export const put = config => {
    return Service({
        ...config,
        // method: "patch",     //局部更改
        method: "put",  //全部更改
        data: config.data        
    })
}